<html>
<head>
  <title>WebChat | 登陆</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="source/css/login.css" rel='stylesheet' type='text/css' />
  <script src="plugins/jquery/jquery-2.1.4.min.js"></script>
  <script src="plugins/layer/layer.js"></script>
  <script language="JavaScript">
    function login(event) {
      event.preventDefault();
      var userid=$("input[name='userid']").val();
      var password=$("input[name='password']").val();

      if(userid==""||password==""){
        alert("不能为空");
        return;
      }
      var data={"userid":userid,"password":password};
      $.ajax({
        type:"post",
        url: "login",
        sync:true,
        data: JSON.stringify(data),//后台接受时使用了@RequestBody注解，需要Json字符串和指定contentType
        contentType:"application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
          if(data.status=="false"){
            alert(data.msg);
            return;
          }
          if(data.status=="true"){
            alert("登录成功");
            window.location.href = "index.html";
          }
        }
      });
    }
    function reg(event) {
      event.preventDefault();
      window.location.href = "register.html";
    }
  </script>
</head>
<body>

<h1>WebChat</h1>
<div class="login-form">
  <div class="close"> </div>
  <div class="head-info">
    <label class="lbl-1"></label>
    <label class="lbl-2"></label>
    <label class="lbl-3"></label>
  </div>
  <div class="clear"> </div>
  <div class="avtar"><img src="source/img/avtar.png" alt="点我注册"/></div>
  <form id="login-form" action="index.html" method="post" onSubmit="return checkLoginForm()">
    <div class="key">
      <input type="text" id="username" name="userid" placeholder="请输入账号" >
    </div>

    <div class="key">
      <input type="password" id="password" name="password" placeholder="请输入密码">
    </div>
     
   
    <div style="height:70px;">  
     <div class="signin" style="float:left;width:50%;">
      <input type="submit" value="Login" onclick="login(event)" />
    </div>   
     <div class="signin" style="float:left;width:50%;">
      <input type="submit"   value="Register" onclick="reg(event)" />
    </div>    
    </div>
  </form>
</div>

<script>
<!--  -->

//  /**
//   * check the login form before user login.
//   * @returns {boolean}
//   */
//  function checkLoginForm(){
//    var username = $('#username').val();
//    var password = $('#password').val();
//    if(isNull(username) && isNull(password)){
//      $('#submit').attr('value','请输入账号和密码!!!').css('background','red');
//      return false;
//    }
//    if(isNull(username)){
//      $('#submit').attr('value','请输入账号!!!').css('background','red');
//      return false;
//    }
//    if(isNull(password)){
//      $('#submit').attr('value','请输入密码!!!').css('background','red');
//      return false;
//    }
//    //if(username != 'Amaya' || password != '123456'){
//    //	$('#submit').attr('value','账号或密码错误!!!').css('background','red');
//    //	return false;
//    //}
//    else{
//      $('#submit').attr('value','Logining~');
//      return true;
//    }
//  }
//
//  /**
//   * check the param if it's null or '' or undefined
//   * @param input
//   * @returns {boolean}
//   */
//  function isNull(input){
//    if(input == null || input == '' || input == undefined){
//      return true;
//    }
//    else{
//      return false;
//    }
//  }
</script>
</body>
</html>